using System;
using Clandestine.Base;
using Clandestine.Engines.Field;
using Qyoto;

namespace Shlick
{
	public class LayerMenu : QObject, IContextMenu
	{
		public MapDocument MapDocument { get; private set; }
		public Layer Layer { get; private set; }
		public LayerTreeView TreeView { get; private set; }
		private QMenu menu;
		
		public LayerMenu (LayerTreeView parent, MapDocument mapDocument, Layer layer)
		{
			this.MapDocument = mapDocument;
			this.Layer = layer;
			this.TreeView = parent;
			
			// Make menu!
			menu = new QMenu(parent);
			menu.AddAction(new QIcon(":/tango/scalable/actions/list-add.svg"), "Add New Layer Above", this, SLOT("onAddSelect()"));
			menu.AddAction(new QIcon(":/tango/scalable/actions/edit-delete.svg"), "Delete Layer", this, SLOT("onDeleteSelect()"));
		}
		
		public void Show()
		{
			menu.Exec(QCursor.Pos());
		}
		
		[Q_SLOT("onAddSelect()")]
		private void onAddSelect()
		{	
			Log.i("Command needed.");
			TreeView.BeginChange();
			Layer.ContainingGroup.AddLayer(new Layer(Layer.ContainingGroup), Layer.Depth + 1);
			TreeView.EndChange();
		}
		
		[Q_SLOT("onDeleteSelect()")]
		private void onDeleteSelect()
		{
			Log.i("Command needed.");
			TreeView.BeginChange();
			Layer.ContainingGroup.RemoveLayer(Layer.Depth);
			TreeView.EndChange();
		}
	}
}

